//Clear all data
clear all

//Set numeric type
set type double

//Set width of figure
local widthPix = 5000


// Change directory - Alter this command to the local copy of the "PrimaryModel" directory
cd "/Users/connorforsythe/Library/CloudStorage/Box-Box/CMU/Marginal Mileage Project/Publication Replication Code/NBER/PrimaryModel"
//Prevent graphics from popping up while running code
set graphics off

//determine log location depending on OS
if("`c(os)'"=="Windows"){
// 	log using "Logs\PrimaryModel.smcl", replace
	local tableSaveDir = "Tables\"
	local plotSaveDir = "Plots\"
	local pythonSaveDir = "PythonScripts\"
}
else{
// 	log using "Logs/PrimaryModel.smcl", replace
	local tableSaveDir = "Tables/"
	local plotSaveDir = "Plots/"
	local pythonSaveDir = "PythonScripts/"
}

//Execute Stata Do File to load and clean the data for VMT models
do LoadDataVMT

sort stateGroup year
by stateGroup: egen treatYearPre = min(year) if nosafetyind==1
by stateGroup: egen treatYear = mean(treatYearPre)
qui sum year
replace treatYear = `r(max)'+1 if treatYear==.

//Establish Control Variable Sets
//Spec1 controls are the same for both registrations and VMT 
local continuousControls = "asinhMetroPop asinhNonMetroPop asinhMetroInc asinhNonMetroInc logrealmeangasprice logemployment loglicenseddrivers logrealstategdp logroadmileage"
local unitControls = "year"
//Binary controls are relevant only to registration data
local binaryControls = "transactionDataDummy"

drop if treatYear==1970

//Run first stage event study using did_imputation; uses same bounds as the shorter window event study
// did_imputation logregistrations stateGroup year treatYear, h(0(1)5) pretrend(5) autosample fe(`binaryControls') unitcontrols(`unitControls') controls(`continuousControls') minn(0) 
did_imputation logregistrations stateGroup year treatYear, autosample fe(`binaryControls') unitcontrols(`unitControls') controls(`continuousControls') minn(0) nose
// cap: did_imputation logvmt stateGroup year treatYear, h(0(1)5) pretrend(5) autosample fe(`binaryControls') unitcontrols(`unitControls') controls(`continuousControls') minn(0) 

//Aggregate Coefficient Estimation

// did_imputation logregistrations stateGroup year treatYear, h(0(1)5) pretrend(5) autosample unitcontrols(c.year) controls(`continuousControls' `binaryControls') minn(0) nose
// did_imputation logregistrations stateGroup year treatYear, h(0(1)5) pretrend(5) autosample unitcontrols(`unitControls') controls(`continuousControls' `binaryControls') minn(0) nose
// did_imputation logregistrations stateGroup year treatYear, h(0(1)5) pretrend(5) autosample fe(`binaryControls') unitcontrols(`unitControls') controls(`continuousControls') minn(0) nose
// did_imputation logregistrations stateGroup year treatYear, h(0(1)5) pretrend(5) autosample fe(`binaryControls') unitcontrols(`unitControls') controls(`continuousControls') minn(0) nose maxit(1000)
// cap: did_imputation logvmt stateGroup year treatYear, autosample fe(`binaryControls') unitcontrols(`unitControls') controls(`continuousControls') minn(0) 



// //Execute Stata Do File to load and clean the data for fuel use models
// do LoadDataGasUse
